﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using ExplorerPlus.DomainObjects;
using ExplorerPlus.PersistenceLayer.Sql;
using ExplorerPlus.PersistenceLayer.Xml;

namespace ExplorerPlus.PersistenceLayer
{
    public static class PersistenceLayerFacade
    {
        private static IPersistence store;
        private static IPersistence Storage
        {
            get 
            {
                if (store == null)
                {
                    store = new XmlPersistence();
                }

                return store;
            }
        }

        public static List<FlyWeightItem> GetFlyWeightCategories()
        {
            return Storage.GetFlyWeightCategories();
        }

        public static List<FlyWeightItem> GetFlyWeightCategoryFields(int categoryId)
        {
            return Storage.GetFlyWeightCategoryFields(categoryId);
        }

        public static List<FlyWeightItem> GetFlyWeightCategoryFieldItems(int categoryId, int fieldId)
        {
            return Storage.GetFlyWeightCategoryFieldItems(categoryId, fieldId);
        }

        public static List<FlyWeightItem> GetFlyWeightItems(int categoryId, int fieldId, string fieldValue)
        {
            return Storage.GetFlyWeightItems(categoryId, fieldId, fieldValue);
        }

        public static Item GetItem(int categoryId, int itemId)
        {
            return Storage.GetItem(categoryId, itemId);
        }

        public static Item GetItemByName(int categoryId, string name)
        {
            return Storage.GetItemByName(categoryId, name);
        }

        public static Plugin GetCategoryPlugins(int categoryId)
        {
            return Storage.GetCategoryPlugins(categoryId);
        }

        public static bool SaveItem(Item item)
        {
            return Storage.SaveItem(item);
        }

        public static void DeleteItem(int categoryId, int itemId)
        {
            Storage.DeleteItem(categoryId, itemId);
        }

        public static void ClearCache()
        {
            if (Storage != null && Storage is XmlPersistence)
            {
                (Storage as XmlPersistence).ClearCache();
            }
        }
    }
}
